<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>待报价列表</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm">
                        <div class="row">
                            <div class="form-inline">
                                <input type="hidden" id="quoteTaskIds" name="quoteTaskIds">
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" name="proName" class="form-control" placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" name="proCode" class="form-control" placeholder="请输入项目编号">
                                </div>
                                <div class="form-group" type="hidden" >
                                    <label>报价状态</label>
                                    <select name="quoteProcessStatus" class="form-control" onchange="changeQuoteStatus(this.value)">
                                        <option value=1 selected="selected">未开始</option>
                                        <option value=2>执行中</option>
                                        <option value=3>已完成</option>
                                        <option value="">全部</option>
                                    </select>
                                </div>
                                <div class="form-group" >
                                    <label>报价状态</label>
                                    <select name="budgetProcessStatus" id="budgetProcessStatus" class="form-control">
                                        <option value=3 selected="selected">待报价</option>
                                        <option value="">全部</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>任务下达日期</label>
                                    <input type="text" class="form-control datepicker" name="quoteStartDate" placeholder="请选择">
                                    <span>至</span>
                                    <input type="text" class="form-control datepicker"  name="quoteEndDate" placeholder="请选择">
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search">
                                    <span class="Bold">&emsp;搜索&emsp;</span>
                                </button>
                            </div>
                        </div>
                        <!--<div id="toolbar">-->
                            <!--<button type="button" class="btn btn-success pull-right" style="margin-right: 10px"  onclick="submitQuote()">-->
                                <!--<span class="Bold">创建报价单</span>-->
                            <!--</button>-->
                        <!--</div>-->
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>

<div th:include="include :: footer"></div>

<script th:inline="javascript">
    /**
     *全选
     */
    function selectedAll() {
        if ($('.checkboxAll').is(":checked")) {
            $('.checkbox_select').each(function () {
                this.checked = true;
            });
        } else {
            $('.checkbox_select').each(function () {
                this.checked = false;
            });
        }
    }

    // 批量提交
    function submitQuote() {
        //获取checkbox[name='check']的值
        var quoteTaskIds = new Array();
        $('input[name="checkbox_select"]:checkbox:checked').each(function(i,value){

            quoteTaskIds += $(this).attr("value")+",";
        });
        if (quoteTaskIds.length <= 0) {
            js.modal.warning("请至少选择一个标记信息");
            return false;
        }
        quoteTaskIds = quoteTaskIds.substring(0,quoteTaskIds.length-1);
        js.modal.confirm("确定多个报价任务创建一个报价单吗？", function () {
             location.href= ctx+'quoteManage/createQuotation/page?quoteTaskIds='+quoteTaskIds
          });
    };

    // 报价任务更改为时设定预算状态
    function changeQuoteStatus(quoteValue){

        if(quoteValue == 2 || quoteValue ==3 || quoteValue ==null||quoteValue ==''){
            $("#budgetProcessStatus").val('');
            $("#budgetProcessStatus").prop("disabled", true);
        }else {
            $("#budgetProcessStatus").val(3);
            $("#budgetProcessStatus").prop("disabled", false);
        }
    }

    var table;
    $(function () {
        /**
         * 加载列表
         */
        table = js.table.init({
            url: ctx + "quoteManage/quoteTaskList/list",
            showColumns: true,
            showExport: true,
            onLoadSuccess: function (data) {
                var dataSource = $('#bootstrap-table').bootstrapTable('getData', true);
            },
            columns: [
                // {
                //     title:'<input class="checkboxAll"  type="checkbox" onclick="selectedAll()" >',width: '40',
                //     formatter: function (value, row, index) {
                //         if (row.quoteStatus == 0 && row.budgetProcessStatus == 3) {
                //             return '<input class="checkbox_select"  type="checkbox" name= "checkbox_select" value="' + $('<div/>').text(row.quoteTaskId).html() + '">';
                //         } else {
                //             return "";
                //         }
                //     }
                // },
                {
                    title: '序号', field: 'id', width: '60',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                {title: '项目名称', field: 'proName', width: '250'},
                {title: '项目编号', field: 'proCode', width: '150'},
                {title: '买方名称', field: 'consumerName', width: '250'},
                {title: '数量', field: 'proQty', width: '100'},
                {title: '单位', field: 'proUnit', width: '100'},
                {title: '概算状态', field: 'budgetProcessStatus', width: '150',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge ' + ["label-default"] + '">' + '未开始' + '</span> ';
                        }else if (value === 2) {
                            return '<span class="badge ' + ["label-info"] + '">' + '执行中' + '</span> ';
                        }else if(value === 3){
                            return '<span class="badge ' + ["label-success"] + '">' + '已完成' + '</span> ';
                        }
                    }
                },
                {title: '报价状态', field: 'quoteProcessStatus', width: '150',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge ' + ["label-default"] + '">' + '未开始' + '</span> ';
                        }else if (value === 2) {
                            return '<span class="badge ' + ["label-info"] + '">' + '执行中' + '</span> ';
                        }else if(value === 3){
                            return '<span class="badge ' + ["label-success"] + '">' + '已完成' + '</span> ';
                        }
                    }
                },
                {title: '任务下达日期', field: 'assignTime', width: '150'},
                {title: '操作', width: '100',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.quoteProcessStatus == 1 && row.budgetProcessStatus == 3) {
                            // if (hasP("quo:list:quotation")) {
                                actions.push('<a class="btn btn-success btn-xs" href="' + ctx + 'quoteManage/createQuotation/page/' + row.quoteTaskId + '">创建报价</a> ');
                            // }
                        }
                        if(row.budgetProcessStatus == 3){
                            // if (hasP("quo:await:download")) {
                                actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openBudget(' + row.quoteTaskId + ')"> 查看概算</a> ');
                            // }
                        }else{
                            return actions.join('');
                        }
                        if(row.quoteProcessStatus == 2 || row.quoteProcessStatus == 3){
                            // if (hasP("quo:await:view")) {
                                actions.push('<a class="btn btn-info btn-xs" href="' + ctx + 'quoteManage/viewQuotation/quoteTaskId/' + row.quoteTaskId + '">查看报价</a> ');
                            // }
                        }else{
                            return actions.join('');
                        }
                        return actions.join('');
                    }
                }
            ]
        });

        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.search(table);
        });

        /**
         * 模态框隐藏事件， 重置表单，重置验证
         */
        js.modal.hideEvent("modal-edit", function () {
            js.validate.reset("halfAdjEditForm");
            js.reset("halfAdjEditForm");
        });
    });
</script>
</body>
</html>